/*
	网络请求 api 合集
*/
const url = 'https://test.glass-china.com'
// let url = 'https://172.19.1.23'
//用户操作
let request = {
    //全局接口
    // axios(info){
    // 	uni.request({
    // 		url:`${url}${info.url}`,
    // 		method: info.method,
    // 		header: {
    // 			'Authorization': uni.getStorageSync('Userinfo').token, // 这里的 token 是你的实际 token
    // 			'Content-Type': 'application/json'
    // 		},
    // 		success: info.success
    // 	})
    // },
    //主页列表接口
    indexList(res) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}/api/phone.Phone/MeetingList`,
                method: 'POST',
                header: {
                    'Authorization': uni.getStorageSync('UserInfo').token,
                    'Content-Type': 'application/json'
                },
                data: res,
                success: (res) => {
                    // 处理首页列表的逻辑
                    resolve(res.data);
                },
            })
        });
    },
    //登录接口
    userlogin(res) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}/admin/Login/check`,
                method: 'POST',
                data: res,
                success: (res) => {
                    // 处理登录成功的逻辑
                    resolve(res.data);
                },
            })
        });
    },
    //提交会议信息接口
    subinfo(res) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}`,
                method: 'POST',
                header: {
                    'Authorization': uni.getStorageSync('UserInfo').token,
                    'Content-Type': 'application/json'
                },
                data: res,
                success: (res) => {
                    // 处理登录成功的逻辑
                    resolve(res.data);
                },
            })
        });
    },
    //会议室列表
    ListMeetingRooms() {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}/api/phone.Phone/MeetingRoomList`,
                method: 'POST',
                header: {
                    'Authorization': uni.getStorageSync('UserInfo').token,
                    'Content-Type': 'application/json'
                },
                // data: res,
                success: (res) => {
                    resolve(res.data);
                },
                fail: (res) => {
                    if (res === '无效或过期的Token') {
                        uni.showToast({
                            title: '登录过期',
                            icon:'error'
                        });
                        uni.clearStorageSync()
                        uni.redirectTo({ url: '/pages/login/login' })
                    }
                    reject(res)
                }
            })
        });
    },
    //上传文件
    upFile(res) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}/api/phone.Phone/UploadFile`,
                method: 'POST',
                header: {
                    'Authorization': uni.getStorageSync('UserInfo').token,
                },
                data: res,
                success: (res) => {
                    resolve(res.data);
                },
                fail: (res) => {
                    reject(res);
                }
            })
        });
    },
    occupation() {
        return new Promise((resolve, reject) => {
            uni.request({
                url: `${url}/api/phone.Phone/MeetingRoomTime`,
                method: 'POST',
                header: {
                    'Authorization': uni.getStorageSync('UserInfo').token,
                    'Content-Type': 'application/json'
                },
                success: (res) => {
                    resolve(res.data);
                },
            })
        });
    }

}
    // [
    // {
    //     "MeetingRoomID": "测试会议室ID11111",
    //     "MeetingRoomName": "测试会议室1",
    //     "MeetingRoomCapacity": 15,
    //     "time": [
    //         {
    //             "MeetingBeginTime": 1721545200,
    //             "MeetingEndTime": 1721547000
    //         },
    //         {
    //             "MeetingBeginTime": 1721610000,
    //             "MeetingEndTime": 1721620800
    //         },
    //         {
    //             "MeetingBeginTime": 1721686326,
    //             "MeetingEndTime": 1721686326
    //         }
    //     ]
    // },
    //     {
    //         "MeetingRoomID": "测试会议室ID22222",
    //         "MeetingRoomName": "测试会议室2",
    //         "MeetingRoomCapacity": 20,
    //         "time": [
    //             {
    //                 "MeetingBeginTime": 1721552400,
    //                 "MeetingEndTime": 1721556000
    //             }
    //         ]
    //     }
    // ]

export {
    request,
    url
};
